﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestComData4ZigBee
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            byte byteData = 0xD2;
            byte test = 0x03;
            byte rData = (byte)(byteData & test);
            rData = (byte)(rData >> 1);



            char cc = 'þ';
            byte cb = 0xFE;
            int cn = 0xFE;
            if (cn == cb)
            {
                int aaa = 100;
                aaa++;
            }


        }

        ZigBeeLibrary.ZigBee mZigBee;
        bool isStop = false;
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            ZigBeeLibrary.ComSettingModel comSettingModel  = new ZigBeeLibrary.ComSettingModel();
            comSettingModel.ZigbeeCom = "COM2";
            mZigBee = new ZigBeeLibrary.ZigBee(comSettingModel);

            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ReadData));
            thread.Start();
        }
        private void ReadData(object obj)
        {
            while (isStop == false)
            {
                bool bRet =  mZigBee.GetSet();
                if (mZigBee.OriginalData != null)
                    Tool.HandlerData(mZigBee.OriginalData, mZigBee.OriginalData.Length);
            }
        }

        private void Window_Closed_1(object sender, EventArgs e)
        {
            isStop = true;
            if (mZigBee != null)
                mZigBee.Close();
        }
    }
}
